$(document).ready(function(){
  order_init();
});

/**
 * init
 */
function order_init() {
    $(".menubutton").click(function(){
        //only react to change menu event with hasClass check
        if($(this).hasClass('activemenu') === false){
            $(".activemenu").removeClass('activemenu');
            $(this).addClass('activemenu');
            // menu change action
            $(".dishbutton").removeClass('visibledish').removeClass('activedish');
            $data = {food_category_id:  $(this).attr('id')};
            $.ajax({
                type: "POST",
                url: "index.php/order/order_main/change_food_category",
                dataType: "json",
                data: $data,
                success: function(msg){
                    //use jquery helper function to loop through json
                    $.each(msg, function(){
                        if(this.en_name !== '[EMPTY]')
                        {
                            dish_id = this.sequence + '-dish';
                            $('#' + dish_id).html(this.en_name).addClass('visibledish');
                        }
                    });
                }
            });
        }
    });

    $(".dishbutton").click(function(){
        //only react to change dish event with hasClass check
        if($(this).hasClass('activedish') === false){
            $(".activedish").removeClass('activedish');
            $(this).addClass('activedish');
        }
    });
}